<template>
  <div align="center">
    <h2>门店增加信息</h2>
    <table border="1">
      <tr>
        <td>门店名称</td>
        <td>
          <input type="text" v-model="state.sname">
        </td>
      </tr>
      <tr>
        <td>门店联系电话</td>
        <td><input type="text" v-model="state.sphone"></td>
      </tr>
      <tr>
        <td>门店地址</td>
        <td><input type="text" v-model="state.saddr"></td>
      </tr>
      <tr>
        <td>门店照片</td>
        <td>
          <input type="file">
        </td>
      </tr>
      <tr>
        <td>门店备注</td>
        <td>
          <textarea rows="5" cols="50" v-model="state.sinfo"></textarea>
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="增加" @click="add">
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
let router = useRouter()

let data = reactive({
  state:{
    sname:'',
    sphone:'',
    saddr:'',
    sphoto:'',
    sinfo:'',
    isDeleted:true
  },
  src:''
})
let {state,src} = toRefs(data)

const add=()=>{
  if(state.value.sname == ""){
    return alert("门店名称不能为空")
  }
  if(state.value.sphone == ""){
    return alert("联系方式不能为空");
  }
  if(state.value.saddr == ""){
    return alert("门店地址不能为空");
  }
  if(state.value.saddr.length < 6){
    return alert("地址必须大于6个字符");
  }
  if(state.value.sinfo == ""){
    return alert("门店备注不能为空");
  }
 
  axios({
    url:'/api/Store/PostAddStore',
    method:'post',
    data:state.value
  })
  .then(res=>{
    console.log(res)
    if(res.data.data > 0){
      alert("门店增加成功");
      router.push('/storelist')
    }
    else if(res.data.data == -1){
      alert("门店名称已存在")
      return;
    }
    else{
      alert("添加失败");
      return
    }
  })
  .catch(err=>{
    console.log(err)
  })
}
</script>

<style scoped>

</style>